package com.itheima.cloud.controller;

import com.itheima.cloud.pojo.User;
import com.itheima.cloud.service.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/user")
public class UserController {
    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }

    @GetMapping("/{id}")
   // @HystrixCommand(fallbackMethod = "queryByIdFallback")
    public User queryById(@PathVariable("id") Long id, HttpServletRequest request) throws InterruptedException {
        if (id==1){
             Thread.sleep(2000);
//            throw new IllegalArgumentException("gg");
        }
        return userService.queryById(id);
    }
    public User queryByIdFallback(@PathVariable("id") Long id,HttpServletRequest request) {
        User user = new User();
        user.setName("爆炸");
        return user;
    }
}
